package leetcode.code0769;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int maxChunksToSorted(int[] arr) {
		int ans = 0;
		int max = 0, min = 0, l = 0;
		for (int r = 0; r < arr.length; r++) {
			max = Math.max(arr[r], max);
			if (max - min == r - l) {
				ans += 1;
				max += 1;
				min = max;
				l = r + 1;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(1, this.maxChunksToSorted(H.str2array3("[4,3,2,1,0]")));
		H.compare(4, this.maxChunksToSorted(H.str2array3("[1,0,2,3,4]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
